/*
 * Created on 2007��5��21��, ����10:20
 * �ı���ڵ��¼
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.XSQS.storage.record;

/**
 *
 * @author Jofee.Chan
 */
public class TRecord implements Record{
    
    private int sIndex;
    private int eIndex;
    private int level;
    private int type;
    private int offset;
    private int length;
    private int parent;
    private int sibling;

    /** Creates a new instance of TRecord */
    public TRecord() {
    }
    
    public TRecord(short[] record){
        setRecord(record);
    }

    public int[] getRecord(){
    	int[] record = new int[8];
        record[0] = sIndex;
        record[1] = eIndex;
        record[2] = level;
        record[3] = type;
        //update by DLS
        int offsetHight=offset>>16;
        int offsetLow=offset&0x0000ffff;
        
        record[4] = offsetHight;
        record[5]=offsetLow;
        record[6] = length;
        record[7] = parent;
//        record[7] = sibling;
        return record;
    }
    
    public void setRecord(short[] record){
    	if(record.length == 8){
            sIndex = record[0];
            eIndex = record[1];
            level = record[2];
            type = record[3];
            offset = (char)record[4];
            offset<<=16;
            offset+=(char)record[5];
            length = record[6];
            parent = record[7];
            if(offset<0){
            	System.err.println("offset<0 "+offset);
            }
        }else{
            System.err.println("Invalid Param!! Array Size: " + record.length);
        }
    }
    
    public String toString(){
        StringBuffer sb = new StringBuffer();
        sb.append(sIndex + " | ");
        sb.append(eIndex + " | ");
        sb.append(level + " | ");
        sb.append(type + " | ");
        sb.append(offset + " | ");
        sb.append(length + " | ");
        sb.append(parent + " | ");
        sb.append(sibling);
        return sb.toString();
    }
    
    public int getSIndex() {
        return sIndex;
    }

    public void setSIndex(int sIndex) {
        this.sIndex = sIndex;
    }

    public int getEIndex() {
        return eIndex;
    }

    public void setEIndex(int eIndex) {
        this.eIndex = eIndex;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getParent() {
        return parent;
    }

    public void setParent(int parent) {
        this.parent = parent;
    }

    public int getSibling() {
        return sibling;
    }

    public void setSibling(int sibling) {
        this.sibling = sibling;
    }
    
}